Repository navigation
fix: stress-run hardening; no website scans until the operator links it - #5
Merged
Merged
Conversation
A page on a DNS name rebound to 127.0.0.1 is same-origin with the helper, so CORS never applies: it could start scans, read PDFs and post /shutdown. before_request now answers 403 invalid_host unless the Host header names localhost, 127.0.0.1 or [::1]. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Any website could shut ScanLink down with a plain cross-site form post, which needs no CORS preflight. Requests to non-browser endpoints that carry Origin or Sec-Fetch-Site now get 403 local_only; the protocol forwarder, PowerShell smoke test and curl send neither header. Co-Authored-By: Claude Opus 5.5 <[email protected]>
With the default cors_origins ["*"], any website could poll /health, read active_job_id from a 409 during an operator's scan, then download the PDF before the DjangoLux page (which then got 410). Jobs now record the request Origin; status/result answer 404 to other origins and busy responses only reveal active_job_id to the owner. Requests from an Origin outside a configured allow-list are refused with 403 before any work. Co-Authored-By: Claude Opus 5.5 <[email protected]>
A 64 MB metadata body was accepted, retained with the job for its TTL and echoed by each 1 Hz status poll (+270 MB RSS per request). MAX_CONTENT_LENGTH now rejects it with 413 payload_too_large before any job is created, and werkzeug HTTP errors use the documented JSON error shape with CORS headers so the page can show them. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Chromium sends Access-Control-Request-Private-Network: true when a public page calls a loopback address and, where PNA is enforced, blocks the request unless the preflight allows it. Allowed origins now get Access-Control-Allow-Private-Network: true. Co-Authored-By: Claude Opus 5.5 <[email protected]>
…le sockets werkzeug wraps the listening socket, so SSLSocket.accept() ran each TLS handshake in the single serve_forever thread: one TCP connection to :5443 that never sent a ClientHello blocked every HTTPS client indefinitely. The HTTPS listener now accepts with do_handshake_on_connect=False and LoopbackRequestHandler handshakes in the connection thread under a 30-second socket timeout, which also closes half-sent HTTP requests that previously held a thread forever. Co-Authored-By: Claude Opus 5.5 <[email protected]>
…ding The scan child kept every page as a decoded RGB image (~26 MB per A4 page at 300 DPI) and _create_pdf decoded each JPEG again through ImageReader, whose getRGBData() digest copy reportlab keeps until save(). 20 pages at 300 DPI or 60 pages at 200 DPI peaked near 2 GB, beyond a 32-bit (x86) build's address space, which the target 32-bit TWAIN driver requires. Pages are now JPEG-encoded on arrival with the same quality settings and drawn from temporary JPEG files, which reportlab embeds as-is: peak RSS 175-200 MB, identical image streams in the PDF. Co-Authored-By: Claude Opus 5.5 <[email protected]>
The scanlink:// handler is registered as "ScanLink.exe" "%1". A launcher that does not escape quotes could inject --scan-worker-dir pointing at any folder or a \\host\share path: the child would read request.json there (sending NTLM credentials to the share), scan whatever is in the feeder and write result.pdf to it. run_scan_job() now exits with 1 unless the directory is a scanlink-job-* folder directly inside tempfile.gettempdir(), the only kind ScanWorker creates. Co-Authored-By: Claude Opus 5.5 <[email protected]>
…ne line is_existing_instance_running() treated any 200 from 127.0.0.1:5000/health as a running ScanLink and forward_protocol_command() any 2xx/409 as a hand-off, so another program on port 5000 made ScanLink exit at startup and silently dropped protocol scans. Both now require ScanLink's JSON answers. parse_protocol_url() logged the raw URL on failure, letting a crafted scanlink:// link forge scanner.log lines; values are now logged with %r. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Developer guide states the Host check, what the default ["*"] allows and that jobs belong to their Origin. Tracker records the branch, the open wildcard-origin decision, the DjangoLux timeout/error-code gaps and the validation run. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]>
The default cors_origins ["*"] (saved in existing config.json files) let every website the operator opened start a scan and download it, silently once a default scanner was saved. Owner decision: DjangoLux supplies its own sites, so the admin chooses which websites may scan. - cors_origins defaults to [] and wildcards are ignored on load. - POST /link (sites.SiteRegistry): a website asks to link, naming the sites its administrator allows. An unlinked website opens an approval window (gui.dialogs.confirm_site_link) that names the requesting origin as the browser sent it; one window at a time, 120 s, and a declined website cannot ask again for 10 minutes. A linked website replaces its list without asking. Links persist in config.json linked_sites. - Browser endpoints answer CORS for any well-formed origin, so an unlinked website reads 403 origin_not_allowed and can offer to link; the work itself stays gated. GET /health reports the site's link. - Tray menu: Linked Websites lists links and unlinks them. - scanlink.js: link(sites), and checkHealth() reports origin_not_allowed instead of helper_unavailable. Co-Authored-By: Claude Opus 5.5 <[email protected]>
debeski
added a commit
to debeski/django-lux
that referenced
this pull request
Nov 14, 2026
… the sites (#74) ## Summary **Security, paired with ScanLink 0.8.0 (debeski/ScanLink#5):** ScanLink no longer lets every website the operator opens scan. Each site is allowed once, in ScanLink's own window, and the DjangoLux administrator chooses which other sites ScanLink allows (owner decision). - **Linking on first scan:** `window.DluxScan.scan()` links an unlinked site (`POST /link`) and shows *Choose Allow in the ScanLink window on this computer to let this site scan*. When the operator chooses Allow, the scan carries on. A linked site whose admin list changed is updated without asking. - **Options → ScanLink:** a refused site shows *Not allowed here*, with an **Allow this site in ScanLink** button (`DluxScan.link()`). - **System Settings → Extra Features:** new field **Other websites that may use ScanLink**, one address per line, validated as website origins, at most 19. - Stored in `extra_config['scanlink']['sites']`. - Helpers: `normalize_scanlink_origin()`, `normalize_scanlink_sites()` and `scanlink_sites()`. - Reaches every page once, as `json_script` `dlux-scanlink-sites` in `base.html`. - **`main.js`:** reports `origin_not_allowed` instead of `helper_unavailable`, and adds `ScanLink.link(sites)`. It stays identical to ScanLink's `static/scanlink.js` apart from one existing line. - **Messages:** `link_declined`, `link_timeout` and `link_pending` are translated (en + ar). - **Docs:** `docs/scanlink.md` (Allowed websites, error codes, compatible versions) and `docs/reference.md`. Stacked on #71 (it maps ScanLink's error codes in the same `scan_button.js`). Merge #71 first; this PR then retargets `main`. ## Tests - `test_scanlink_sites`: origins, storage, form validation and save, and page data rendered once and only while ScanLink is on. - `scenarios.mjs`: 29 scenarios, also against ScanLink's own client (42). - Full suite: 3,271 OK (6 skipped), run before and after the `json_script` move. - **Live paired check** (`main/.xclude/validation/1.16-stress-2026-11-14/scanlink-links/`): ScanLink's real server and link registry over HTTP, driven by these real page scripts, all seven steps as designed: - link with Allow, then scan; - no re-link when the list is unchanged; - a site on the admin's list scans; - a changed list is sent silently; - a declined site, and the 10-minute cooldown; - an unanswered window times out. - **Browser, testbed-dlux** (Arabic UI, local candidate): - the field renders left-to-right with its help text; - a bad line is refused with a translated error that names it; - a save stores normalised origins and leaves the switch alone; - the list reaches pages as data; - the Options card still says *Not detected* when an unrelated program answers on port 5000. - The browser check found the duplicate `json_script` (the Decrees list includes the form scripts twice), fixed in the second commit. - Not run: the card's Allow flow in a real browser. On this Mac, port 5000 belongs to AirPlay; the Node scenarios cover that flow with the real script. 🤖 Generated with [Claude Code](https://claude.com/claude-code)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Hardening from the 2026-11-14 stress run: HTTPS server concurrency and malformed input, Origin/CORS/DNS rebinding, protocol handler fuzzing, and the DluxScan contract against DjangoLux's real
main.js/scan_button.js.Origin binding: a scan is bound to the origin that started it; another site can no longer read or take a scan.
Host and local-only checks: requests whose
Hostis not loopback are refused (DNS rebinding);/shutdownand the protocol endpoint stay local-only (no form-post shutdown).Private Network Access preflights are answered.
Request bodies: capped at 64 KB; HTTP errors are answered in JSON.
TLS: handshakes complete off the accept loop and idle sockets time out, so one idle connection can no longer freeze the server.
Memory: captured pages stay JPEG and are embedded without decoding (about 2 GB peak on 32-bit builds before).
Scan jobs run only in ScanLink's own temp job directories (no UNC paths).
Protocol handler: verifies the helper's identity and keeps log entries on one line.
Docs and tracker record the hardening state.
No website scans until the operator links it (
2998cd1, owner decision: DjangoLux supplies its sites):cors_originsdefaults to[]and wildcards are ignored, so a saved["*"]no longer lets every website start a silent scan.POST /link(sites.SiteRegistry): a website asks to link and names the sites its administrator allows.gui.dialogs.confirm_site_link). The window names the origin as the browser sent it.config.jsonlinked_sites.403 origin_not_allowed; the work stays gated./healthreports the requesting site'slink.scanlink.js: addslink(sites)and reportsorigin_not_allowed.Tests
tests/test_site_links.pycovers approval, list changes, declines and their cooldown, the one-window rule, timeouts, bad requests, the Host check, unlinking and persistence).SiteRegistryover HTTP, driven by DjangoLux's realmain.jsandscan_button.js, with the scanner mocked:static/scanlink.js(42).Pairs with debeski/django-lux#71 (error codes, wait past the job deadline) and the DjangoLux site-linking PR stacked on it.
🤖 Generated with Claude Code